<?php
class Site_Model_Observer_AttacheAlbum extends Promotor_Observable_Observer_Abstract {
	public function update(Promotor_Observable_List $list, $albumId = null) {
		$rq = $this->getRequest();
		if ((null === ($sites = $rq->getPost('categorytab')))) {
			$this->_setStatus(self::NULL);
			return;
		}
		if (is_array($albumId)) {
			$albumId = isset($albumId['id'])
				? $albumId['id']
				: current($albumId);
		}
		if (null === $albumId) {
			$this->_setStatus(self::NULL);
			return;
		}

		$hasAlbum = new Site_Model_HasAlbum();
		$hasAlbum->attachAlbumToSites($albumId, (array) @$sites['tree']);

		$status = $hasAlbum->getStatus();

		$this->_setStatus($status);
		$this->_setMessages($hasAlbum->getMessages(false));
		$this->_exception = $hasAlbum->getExceptions();
	}
}